package com.springboot.demo.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.springboot.demo.entity.validate.PhoneGroup1;
import com.springboot.demo.entity.validate.PhoneGroup2;
import com.springboot.demo.entity.validate.device.DevClusterNameGroup;
import com.springboot.demo.entity.validate.role.RoleNameGroup;
import com.springboot.demo.entity.validate.user.IdGroup;
import com.springboot.demo.entity.validate.user.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.*;

/**
 * @author wubc683
 * @desc
 * @date 2021-07-22 10:56
 */
@Data
@Slf4j
@ApiModel
@NoArgsConstructor
@AllArgsConstructor
public class User implements Serializable {
    @ApiModelProperty(value = "用户id", required = true)
    @NotNull(message = "id不能为空", groups = IdGroup.class)
    private Long id;
    @ApiModelProperty(value = "用户名:6~32位字符", required = true)
    @NotBlank(message = "用户名不能为空", groups = UsernameGroup.class)
    @Length(min=6,max=32, message = "用户名长度错误", groups = UsernameGroup.class)
    @Pattern(regexp = "^[\\u4E00-\\u9FA5a-zA-Z0-9_-]{6,32}$", message = "用户名格式错误",
            groups = UsernameGroup.class)
    private String username;
    @NotBlank(message = "密码不能为空", groups = PasswordGroup.class)
    @Pattern(regexp = "^[a-zA-Z0-9_-]{6,32}$", message = "密码格式错误",
            groups = PasswordGroup.class)
    @Length(min=6,max=32, message = "密码格式错误", groups = PasswordGroup.class)
    @ApiModelProperty(value = "密码:5~31位字符", required = true)
    private String password;
    @NotBlank(message = "重复密码不能为空", groups = RetryPasswordGroup.class)
    @Length(min=6,max=32, message = "重复密码格式错误",groups = RetryPasswordGroup.class)
    @Pattern(regexp = "^[a-zA-Z0-9_-]{6,32}$", message = "重复密码格式错误",
            groups = RetryPasswordGroup.class)
    @ApiModelProperty(value = "重复密码:6~32位字符", required = true)
    private String retryPassword;
    @NotBlank(message = "旧密码不能为空", groups = oldPasswordGroup.class)
    @Length(min=6,max=32, message = "旧密码格式错误", groups = oldPasswordGroup.class)
    @Pattern(regexp = "^[a-zA-Z0-9_-]{6,32}$", message = "密码格式错误",
            groups = oldPasswordGroup.class)
    @ApiModelProperty(value = "密码:6~32位字符", required = true)
    private String oldPassword;
//    @ApiModelProperty(value = "邮箱")
//    private String email;
    @NotNull(message = "角色id不能为null", groups = RoleIdGroup.class)
    @ApiModelProperty(value = "角色id",required = true)
    private Long rid;
    @ApiModelProperty(value = "关联账号的管理员账号id")
    private Long parentId;
    @NotNull(message = "手机号不能为空", groups = PhoneGroup.class)
    @Pattern(regexp = "^(((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7})|" +
            "(((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7})|" +
            "(((133)|(153)|(177)|(18[0,1,9])|(149))\\d{8})|" +
            "(((170))\\d{8}|(1718)|(1719)\\d{7})$", message = "手机号格式错误", groups = PhoneGroup1.class)
    @Pattern(regexp = "(^\\s*$)|(^(((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7})|" +
            "(((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7})|" +
            "(((133)|(153)|(177)|(18[0,1,9])|(149))\\d{8})|" +
            "(((170))\\d{8}|(1718)|(1719)\\d{7})$)", message = "手机号格式错误", groups = PhoneGroup2.class)
    @ApiModelProperty(value = "手机号",required = true)
    private String phone;
    @NotBlank(message = "公司名称不能为空", groups = CompanyGroup.class)
    @Length(min = 1, max = 63, message = "公司长度错误", groups = {CompanyGroup.class})
    @ApiModelProperty(value = "公司名称,长度1~63", required = true)
    private String company;
    @NotNull(message = "公司所在省份不能为null", groups = CompanyAddrGroup.class)
    @Min(value= 0, message = "公司所在省份错误", groups = {CompanyGroup.class})
    @Max(value= 34, message = "公司所在省份错误", groups = {CompanyGroup.class})
    @ApiModelProperty(value = "公司所在省份,范围0~34", required = true)
    private Integer companyAddr;
    @NotNull(message = "行业类型不能为null", groups = IndustryTypeGroup.class)
    @Min(value = 0, message = "行业类型错误", groups = {IndustryTypeGroup.class})
    @Max(value = 17, message = "行业类型错误", groups = {IndustryTypeGroup.class})
    @ApiModelProperty(value = "行业类型,范围0~17", required = true)
    private Integer industryType;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "上次登录时间")
    private Date lastLoginTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "账号注册日期")
    private Date createDate;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "账号到期日期")
    private Date expireDate;
    @NotBlank(message = "图形验证码不能为空,5位", groups = ImgCodeGroup.class)
    @ApiModelProperty(value = "图形验证码", required = true)
    private String imgCode;
    @NotNull(message = "短信验证码不能为空,6位", groups = SmsCodeGroup.class)
    @ApiModelProperty(value = "短信验证码", required = true)
    private String smsCode;
    @ApiModelProperty(value = "账号是否激活")
    private Boolean isEnabled;
    @ApiModelProperty(value = "账号是否锁定")
    private Boolean isLocked;
    @ApiModelProperty(value = "手机号是否已校验")
    private Boolean isPhoneChecked;
    @ApiModelProperty("历史记录条数")
    private Integer recordCount;
    @ApiModelProperty("是否已删除,空未删除，非空删除")
    private String deleteFlag;
}
